/*     */ package com.zimbra.qa.unittest.prov.ldap;
/*     */ 
/*     */ import com.zimbra.common.account.ZAttrProvisioning.AutoProvAuthMech;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.AutoProvisionThread;
/*     */ import com.zimbra.cs.account.Config;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Provisioning.DirectoryEntryVisitor;
/*     */ import com.zimbra.cs.account.Provisioning.EagerAutoProvisionScheduler;
/*     */ import com.zimbra.cs.account.Server;
/*     */ import com.zimbra.cs.account.auth.AuthContext.Protocol;
/*     */ import com.zimbra.cs.account.auth.AuthMechanism.AuthMech;
/*     */ import com.zimbra.cs.account.ldap.AutoProvisionListener;
/*     */ import com.zimbra.cs.account.ldap.LdapProv;
/*     */ import com.zimbra.cs.ldap.LdapUtil;
/*     */ import com.zimbra.qa.unittest.TestUtil;
/*     */ import com.zimbra.qa.unittest.prov.AutoProvisionTestUtil;
/*     */ import com.zimbra.qa.unittest.prov.AutoProvisionTestUtil.MarkEntryProvisionedListener;
/*     */ import com.zimbra.soap.type.AutoProvPrincipalBy;
/*     */ import java.util.HashMap;
/*     */ import java.util.HashSet;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ import org.junit.AfterClass;
/*     */ import org.junit.Assert;
/*     */ import org.junit.BeforeClass;
/*     */ import org.junit.Test;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestAutoProvision
/*     */   extends LdapTest
/*     */ {
/*     */   private static LdapProvTestUtil provUtil;
/*     */   private static LdapProv prov;
/*     */   private static Domain extDomain;
/*     */   private static String extDomainDn;
/*     */   
/*     */   @BeforeClass
/*     */   public static void init()
/*     */     throws Exception
/*     */   {
/*  61 */     provUtil = new LdapProvTestUtil();
/*  62 */     prov = provUtil.getProv();
/*  63 */     extDomain = provUtil.createDomain("external." + baseDomainName());
/*  64 */     extDomainDn = LdapUtil.domainToDN(extDomain.getName());
/*     */   }
/*     */   
/*     */   @AfterClass
/*     */   public static void cleanup() throws Exception {
/*  69 */     Cleanup.deleteAll(new String[] { baseDomainName() });
/*     */   }
/*     */   
/*     */   private String getZimbraDomainName(String testName) {
/*  73 */     return testName + "." + baseDomainName();
/*     */   }
/*     */   
/*     */   private Domain createZimbraDomain(String testName, Map<String, Object> zimbraDomainAttrs) throws Exception
/*     */   {
/*  78 */     return provUtil.createDomain(getZimbraDomainName(testName), zimbraDomainAttrs);
/*     */   }
/*     */   
/*     */   private String createExternalAcctEntry(String localPart) throws Exception {
/*  82 */     return createExternalAcctEntry(localPart, null);
/*     */   }
/*     */   
/*     */   private String createExternalAcctEntry(String localPart, Map<String, Object> attrs) throws Exception
/*     */   {
/*  87 */     return createExternalAcctEntry(localPart, null, attrs);
/*     */   }
/*     */   
/*     */   private String createExternalAcctEntry(String localPart, String externalPassword, Map<String, Object> attrs) throws Exception
/*     */   {
/*  92 */     String extAcctName = TestUtil.getAddress(localPart, extDomain.getName());
/*     */     
/*  94 */     Map<String, Object> extAcctAttrs = attrs == null ? new HashMap() : attrs;
/*     */     
/*  96 */     extAcctAttrs.put("displayName", "display name");
/*  97 */     extAcctAttrs.put("sn", "last name");
/*  98 */     Account extAcct = prov.createAccount(extAcctName, externalPassword, extAcctAttrs);
/*  99 */     return extAcctName;
/*     */   }
/*     */   
/*     */   private String externalEntryDN(String externalEntryLocalPart) {
/* 103 */     return String.format("uid=%s,ou=people,%s", new Object[] { externalEntryLocalPart, extDomainDn });
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   @Test
/*     */   public void lazyModeGetExternalEntryByDNTemplate()
/*     */     throws Exception
/*     */   {
/* 113 */     String testName = getTestName();
/*     */     
/* 115 */     String extAcctLocalPart = testName;
/* 116 */     String extAcctName = createExternalAcctEntry(extAcctLocalPart);
/*     */     
/* 118 */     Map<String, Object> zimbraDomainAttrs = AutoProvisionTestUtil.commonZimbraDomainAttrs();
/*     */     
/* 120 */     zimbraDomainAttrs.put("zimbraAutoProvLdapBindDn", "uid=%u,ou=people," + extDomainDn);
/* 121 */     Domain zimbraDomain = createZimbraDomain(testName, zimbraDomainAttrs);
/*     */     
/* 123 */     String loginName = extAcctLocalPart;
/* 124 */     Account acct = prov.autoProvAccountLazy(zimbraDomain, loginName, null, ZAttrProvisioning.AutoProvAuthMech.LDAP);
/* 125 */     AutoProvisionTestUtil.verifyAcctAutoProvisioned(acct);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void lazyModeGetExternalEntryBySearch() throws Exception {
/* 130 */     String testName = getTestName();
/*     */     
/* 132 */     String extAcctLocalPart = testName;
/* 133 */     String extAcctName = createExternalAcctEntry(extAcctLocalPart);
/*     */     
/* 135 */     Map<String, Object> zimbraDomainAttrs = AutoProvisionTestUtil.commonZimbraDomainAttrs();
/* 136 */     zimbraDomainAttrs.put("zimbraAutoProvLdapSearchBase", extDomainDn);
/* 137 */     zimbraDomainAttrs.put("zimbraAutoProvLdapSearchFilter", "(uid=%u)");
/* 138 */     Domain zimbraDomain = createZimbraDomain(testName, zimbraDomainAttrs);
/*     */     
/* 140 */     String loginName = extAcctLocalPart;
/* 141 */     Account acct = prov.autoProvAccountLazy(zimbraDomain, loginName, null, ZAttrProvisioning.AutoProvAuthMech.LDAP);
/* 142 */     AutoProvisionTestUtil.verifyAcctAutoProvisioned(acct);
/*     */   }
/*     */   
/*     */   public static class TestListener implements AutoProvisionListener
/*     */   {
/*     */     private static TestListener instance;
/*     */     private Account acct;
/*     */     private String externalDN;
/*     */     
/*     */     public TestListener() {
/* 152 */       Assert.assertNull(instance);
/* 153 */       instance = this;
/*     */     }
/*     */     
/*     */ 
/*     */     public void postCreate(Domain domain, Account acct, String externalDN)
/*     */     {
/* 159 */       this.acct = acct;
/* 160 */       this.externalDN = externalDN;
/*     */     }
/*     */     
/*     */     private static TestListener getInstance()
/*     */     {
/* 165 */       return instance;
/*     */     }
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void lazyModeListener() throws Exception {
/* 171 */     String testName = getTestName();
/*     */     
/* 173 */     String extAcctLocalPart = testName;
/* 174 */     String extAcctName = createExternalAcctEntry(extAcctLocalPart);
/*     */     
/* 176 */     Map<String, Object> zimbraDomainAttrs = AutoProvisionTestUtil.commonZimbraDomainAttrs();
/* 177 */     zimbraDomainAttrs.put("zimbraAutoProvLdapSearchBase", extDomainDn);
/* 178 */     zimbraDomainAttrs.put("zimbraAutoProvLdapSearchFilter", "(uid=%u)");
/*     */     
/*     */ 
/* 181 */     String className = TestListener.class.getName();
/* 182 */     zimbraDomainAttrs.put("zimbraAutoProvListenerClass", className);
/* 183 */     Domain zimbraDomain = createZimbraDomain(testName, zimbraDomainAttrs);
/*     */     
/* 185 */     String loginName = extAcctLocalPart;
/* 186 */     Account acct = prov.autoProvAccountLazy(zimbraDomain, loginName, null, ZAttrProvisioning.AutoProvAuthMech.LDAP);
/* 187 */     AutoProvisionTestUtil.verifyAcctAutoProvisioned(acct);
/*     */     
/* 189 */     TestListener listener = TestListener.access$000();
/* 190 */     Assert.assertNotNull(listener);
/* 191 */     Assert.assertEquals(acct.getId(), listener.acct.getId());
/* 192 */     Assert.assertEquals(externalEntryDN(extAcctLocalPart).toLowerCase(), listener.externalDN);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void lazyModeAccountLocalpartMap() throws Exception {
/* 197 */     String testName = getTestName();
/*     */     
/* 199 */     String extAcctLocalPart = testName;
/* 200 */     String zimbraAcctLocalpart = "myzimbraname";
/* 201 */     Map<String, Object> acctAttrs = new HashMap();
/* 202 */     acctAttrs.put("description", zimbraAcctLocalpart);
/* 203 */     String extAcctName = createExternalAcctEntry(extAcctLocalPart, acctAttrs);
/*     */     
/* 205 */     Map<String, Object> zimbraDomainAttrs = AutoProvisionTestUtil.commonZimbraDomainAttrs();
/* 206 */     zimbraDomainAttrs.put("zimbraAutoProvLdapSearchBase", extDomainDn);
/* 207 */     zimbraDomainAttrs.put("zimbraAutoProvLdapSearchFilter", "(uid=%u)");
/* 208 */     zimbraDomainAttrs.put("zimbraAutoProvAccountNameMap", "description");
/* 209 */     Domain zimbraDomain = createZimbraDomain(testName, zimbraDomainAttrs);
/*     */     
/* 211 */     String loginName = extAcctLocalPart;
/* 212 */     Account acct = prov.autoProvAccountLazy(zimbraDomain, loginName, null, ZAttrProvisioning.AutoProvAuthMech.LDAP);
/* 213 */     AutoProvisionTestUtil.verifyAcctAutoProvisioned(acct, zimbraAcctLocalpart + "@" + zimbraDomain.getName());
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void lazyModeAutoProvNotEnabledByAuthMech() throws Exception {
/* 218 */     String testName = getTestName();
/*     */     
/* 220 */     String extAcctLocalPart = testName;
/* 221 */     String extAcctName = createExternalAcctEntry(extAcctLocalPart);
/*     */     
/* 223 */     Map<String, Object> zimbraDomainAttrs = AutoProvisionTestUtil.commonZimbraDomainAttrs();
/* 224 */     zimbraDomainAttrs.put("zimbraAutoProvLdapBindDn", "uid=%u,ou=people," + extDomainDn);
/* 225 */     Domain zimbraDomain = createZimbraDomain(testName, zimbraDomainAttrs);
/*     */     
/* 227 */     String loginName = extAcctLocalPart;
/* 228 */     Account acct = prov.autoProvAccountLazy(zimbraDomain, loginName, null, ZAttrProvisioning.AutoProvAuthMech.PREAUTH);
/* 229 */     Assert.assertNull(acct);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void lazyModeExternalLdapAuth() throws Exception {
/* 234 */     String testName = getTestName();
/*     */     
/* 236 */     String externalPassword = "test456";
/* 237 */     String extAcctLocalPart = testName;
/* 238 */     String extAcctName = createExternalAcctEntry(extAcctLocalPart, externalPassword, null);
/*     */     
/* 240 */     Map<String, Object> zimbraDomainAttrs = AutoProvisionTestUtil.commonZimbraDomainAttrs();
/*     */     
/* 242 */     zimbraDomainAttrs.put("zimbraAutoProvLdapSearchBase", extDomainDn);
/* 243 */     zimbraDomainAttrs.put("zimbraAutoProvLdapSearchFilter", "(uid=%u)");
/*     */     
/* 245 */     zimbraDomainAttrs.put("zimbraAuthMech", AuthMechanism.AuthMech.ldap.name());
/* 246 */     zimbraDomainAttrs.put("zimbraAuthLdapURL", "ldap://localhost:389");
/* 247 */     zimbraDomainAttrs.put("zimbraAuthLdapBindDn", "uid=%u,ou=people," + extDomainDn);
/* 248 */     Domain zimbraDomain = createZimbraDomain(testName, zimbraDomainAttrs);
/*     */     
/*     */ 
/* 251 */     String loginName = extAcctLocalPart;
/* 252 */     Account acct = prov.autoProvAccountLazy(zimbraDomain, loginName, externalPassword + "bad", null);
/* 253 */     Assert.assertNull(acct);
/*     */     
/*     */ 
/* 256 */     acct = prov.autoProvAccountLazy(zimbraDomain, loginName, externalPassword, null);
/* 257 */     AutoProvisionTestUtil.verifyAcctAutoProvisioned(acct);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   @Test
/*     */   public void manualModeByName()
/*     */     throws Exception
/*     */   {
/* 267 */     String testName = getTestName();
/*     */     
/* 269 */     String externalPassword = "test456";
/* 270 */     String extAcctLocalPart = testName;
/* 271 */     String extAcctName = createExternalAcctEntry(extAcctLocalPart, externalPassword, null);
/*     */     
/* 273 */     Map<String, Object> zimbraDomainAttrs = AutoProvisionTestUtil.commonZimbraDomainAttrs();
/*     */     
/* 275 */     zimbraDomainAttrs.put("zimbraAutoProvLdapSearchBase", extDomainDn);
/* 276 */     zimbraDomainAttrs.put("zimbraAutoProvLdapSearchFilter", "(uid=%u)");
/* 277 */     Domain zimbraDomain = createZimbraDomain(testName, zimbraDomainAttrs);
/*     */     
/* 279 */     String principal = extAcctLocalPart;
/* 280 */     String password = "test123";
/* 281 */     Account acct = prov.autoProvAccountManual(zimbraDomain, AutoProvPrincipalBy.name, principal, password);
/*     */     
/* 283 */     AutoProvisionTestUtil.verifyAcctAutoProvisioned(acct);
/*     */     
/*     */ 
/* 286 */     prov.authAccount(acct, password, AuthContext.Protocol.test);
/*     */     
/* 288 */     boolean caughtException = false;
/*     */     try {
/* 290 */       prov.authAccount(acct, externalPassword, AuthContext.Protocol.test);
/*     */     } catch (ServiceException e) {
/* 292 */       if ("account.AUTH_FAILED".equals(e.getCode())) {
/* 293 */         caughtException = true;
/*     */       }
/*     */     }
/* 296 */     Assert.assertTrue(caughtException);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void manualModeByDN() throws Exception {
/* 301 */     String testName = getTestName();
/*     */     
/* 303 */     String extAcctLocalPart = testName;
/* 304 */     String zimbraAcctLocalpart = "myzimbraname";
/* 305 */     Map<String, Object> acctAttrs = new HashMap();
/* 306 */     acctAttrs.put("description", zimbraAcctLocalpart);
/* 307 */     String extAcctName = createExternalAcctEntry(extAcctLocalPart, acctAttrs);
/*     */     
/* 309 */     Map<String, Object> zimbraDomainAttrs = AutoProvisionTestUtil.commonZimbraDomainAttrs();
/*     */     
/* 311 */     zimbraDomainAttrs.put("zimbraAutoProvLdapSearchBase", extDomainDn);
/* 312 */     zimbraDomainAttrs.put("zimbraAutoProvLdapSearchFilter", "(uid=%u)");
/* 313 */     zimbraDomainAttrs.put("zimbraAutoProvAccountNameMap", "description");
/* 314 */     Domain zimbraDomain = createZimbraDomain(testName, zimbraDomainAttrs);
/*     */     
/* 316 */     String principal = externalEntryDN(extAcctLocalPart);
/* 317 */     String password = null;
/* 318 */     Account acct = prov.autoProvAccountManual(zimbraDomain, AutoProvPrincipalBy.dn, principal, password);
/*     */     
/* 320 */     AutoProvisionTestUtil.verifyAcctAutoProvisioned(acct, zimbraAcctLocalpart + "@" + zimbraDomain.getName());
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void searchAutoProvDirectoryByName() throws Exception {
/* 325 */     String testName = getTestName();
/*     */     
/* 327 */     String externalPassword = "test456";
/* 328 */     String extAcctLocalPart1 = testName + "_1";
/* 329 */     String extAcctLocalPart2 = testName + "_2";
/* 330 */     String extAcctLocalPart3 = testName + "_3";
/* 331 */     createExternalAcctEntry(extAcctLocalPart1, externalPassword, null);
/* 332 */     createExternalAcctEntry(extAcctLocalPart2, externalPassword, null);
/* 333 */     createExternalAcctEntry(extAcctLocalPart3, externalPassword, null);
/*     */     
/* 335 */     Map<String, Object> zimbraDomainAttrs = AutoProvisionTestUtil.commonZimbraDomainAttrs();
/*     */     
/* 337 */     zimbraDomainAttrs.put("zimbraAutoProvLdapSearchBase", extDomainDn);
/* 338 */     zimbraDomainAttrs.put("zimbraAutoProvLdapSearchFilter", "(uid=%u)");
/* 339 */     Domain zimbraDomain = createZimbraDomain(testName, zimbraDomainAttrs);
/*     */     
/* 341 */     final Set<String> entriesFound = new HashSet();
/* 342 */     Provisioning.DirectoryEntryVisitor visitor = new Provisioning.DirectoryEntryVisitor()
/*     */     {
/*     */       public void visit(String dn, Map<String, Object> attrs) {
/* 345 */         entriesFound.add(dn);
/*     */       }
/*     */       
/* 348 */     };
/* 349 */     prov.searchAutoProvDirectory(zimbraDomain, null, extAcctLocalPart2, null, 0, visitor);
/*     */     
/*     */ 
/* 352 */     Assert.assertEquals(1L, entriesFound.size());
/* 353 */     Assert.assertTrue(entriesFound.contains(externalEntryDN(extAcctLocalPart2).toLowerCase()));
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void searchAutoProvDirectoryByProvidedFilter() throws Exception {
/* 358 */     String testName = getTestName();
/*     */     
/* 360 */     String externalPassword = "test456";
/* 361 */     String extAcctLocalPart1 = testName + "_1";
/* 362 */     String extAcctLocalPart2 = testName + "_2";
/* 363 */     String extAcctLocalPart3 = testName + "_3";
/* 364 */     createExternalAcctEntry(extAcctLocalPart1, externalPassword, null);
/* 365 */     createExternalAcctEntry(extAcctLocalPart2, externalPassword, null);
/* 366 */     createExternalAcctEntry(extAcctLocalPart3, externalPassword, null);
/*     */     
/* 368 */     Map<String, Object> zimbraDomainAttrs = AutoProvisionTestUtil.commonZimbraDomainAttrs();
/*     */     
/*     */ 
/*     */ 
/* 372 */     Domain zimbraDomain = createZimbraDomain(testName, zimbraDomainAttrs);
/*     */     
/* 374 */     final Set<String> entriesFound = new HashSet();
/* 375 */     Provisioning.DirectoryEntryVisitor visitor = new Provisioning.DirectoryEntryVisitor()
/*     */     {
/*     */       public void visit(String dn, Map<String, Object> attrs) {
/* 378 */         entriesFound.add(dn);
/*     */       }
/*     */       
/* 381 */     };
/* 382 */     prov.searchAutoProvDirectory(zimbraDomain, String.format("(mail=%s*)", new Object[] { testName }), null, null, 0, visitor);
/*     */     
/*     */ 
/*     */ 
/* 386 */     Assert.assertEquals(3L, entriesFound.size());
/* 387 */     Assert.assertTrue(entriesFound.contains(externalEntryDN(extAcctLocalPart1).toLowerCase()));
/* 388 */     Assert.assertTrue(entriesFound.contains(externalEntryDN(extAcctLocalPart2).toLowerCase()));
/* 389 */     Assert.assertTrue(entriesFound.contains(externalEntryDN(extAcctLocalPart3).toLowerCase()));
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void searchAutoProvDirectoryByConfiguredSearchFilter() throws Exception {
/* 394 */     String testName = getTestName();
/*     */     
/* 396 */     String externalPassword = "test456";
/* 397 */     String extAcctLocalPart1 = testName + "_1";
/* 398 */     String extAcctLocalPart2 = testName + "_2";
/* 399 */     String extAcctLocalPart3 = testName + "_3";
/* 400 */     createExternalAcctEntry(extAcctLocalPart1, externalPassword, null);
/* 401 */     createExternalAcctEntry(extAcctLocalPart2, externalPassword, null);
/* 402 */     createExternalAcctEntry(extAcctLocalPart3, externalPassword, null);
/*     */     
/* 404 */     Map<String, Object> zimbraDomainAttrs = AutoProvisionTestUtil.commonZimbraDomainAttrs();
/*     */     
/* 406 */     zimbraDomainAttrs.put("zimbraAutoProvLdapSearchBase", extDomainDn);
/* 407 */     zimbraDomainAttrs.put("zimbraAutoProvLdapSearchFilter", "(&(uid=%u)(mail=searchAutoProvDirectoryByConfiguredSearchFilter*))");
/*     */     
/* 409 */     Domain zimbraDomain = createZimbraDomain(testName, zimbraDomainAttrs);
/*     */     
/* 411 */     final Set<String> entriesFound = new HashSet();
/* 412 */     Provisioning.DirectoryEntryVisitor visitor = new Provisioning.DirectoryEntryVisitor()
/*     */     {
/*     */       public void visit(String dn, Map<String, Object> attrs) {
/* 415 */         entriesFound.add(dn);
/*     */       }
/*     */       
/* 418 */     };
/* 419 */     prov.searchAutoProvDirectory(zimbraDomain, null, null, null, 0, visitor);
/*     */     
/*     */ 
/* 422 */     Assert.assertEquals(3L, entriesFound.size());
/* 423 */     Assert.assertTrue(entriesFound.contains(externalEntryDN(extAcctLocalPart1).toLowerCase()));
/* 424 */     Assert.assertTrue(entriesFound.contains(externalEntryDN(extAcctLocalPart2).toLowerCase()));
/* 425 */     Assert.assertTrue(entriesFound.contains(externalEntryDN(extAcctLocalPart3).toLowerCase()));
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   @Test
/*     */   public void eagerMode()
/*     */     throws Exception
/*     */   {
/* 434 */     String testName = getTestName();
/*     */     
/* 436 */     String externalPassword = "test456";
/*     */     
/* 438 */     int totalAccts = 4;
/* 439 */     String extAcctLocalPart1 = testName + "_1";
/* 440 */     String extAcctLocalPart2 = "abc";
/* 441 */     String extAcctLocalPart3 = testName + "_3";
/* 442 */     String extAcctLocalPart4 = testName + "_4";
/* 443 */     String extAcctLocalPart5 = testName + "_5";
/* 444 */     createExternalAcctEntry(extAcctLocalPart1, "test456", null);
/* 445 */     createExternalAcctEntry(extAcctLocalPart2, "test456", null);
/* 446 */     createExternalAcctEntry(extAcctLocalPart3, "test456", null);
/* 447 */     createExternalAcctEntry(extAcctLocalPart4, "test456", null);
/* 448 */     createExternalAcctEntry(extAcctLocalPart5, "test456", null);
/*     */     
/* 450 */     Map<String, Object> zimbraDomainAttrs = AutoProvisionTestUtil.commonZimbraDomainAttrs();
/*     */     
/* 452 */     zimbraDomainAttrs.put("zimbraAutoProvLdapSearchBase", extDomainDn);
/* 453 */     zimbraDomainAttrs.put("zimbraAutoProvLdapSearchFilter", "(&(uid=%u)(mail=eagerMode*)(!(zimbraNotes=PROVISIONED IN ZIMBRA)))");
/*     */     
/*     */ 
/* 456 */     zimbraDomainAttrs.put("zimbraAutoProvAccountNameMap", "uid");
/*     */     
/*     */ 
/*     */ 
/* 460 */     int batchSize = totalAccts - 1;
/* 461 */     zimbraDomainAttrs.put("zimbraAutoProvBatchSize", Integer.valueOf(batchSize).toString());
/* 462 */     zimbraDomainAttrs.put("zimbraAutoProvListenerClass", AutoProvisionTestUtil.MarkEntryProvisionedListener.class.getName());
/*     */     
/* 464 */     Domain zimbraDomain = createZimbraDomain(testName, zimbraDomainAttrs);
/*     */     
/*     */ 
/* 467 */     prov.getLocalServer().addAutoProvScheduledDomains(zimbraDomain.getName());
/*     */     
/* 469 */     Provisioning.EagerAutoProvisionScheduler scheduler = new Provisioning.EagerAutoProvisionScheduler()
/*     */     {
/*     */       public boolean isShutDownRequested() {
/* 472 */         return false;
/*     */       }
/*     */       
/* 475 */     };
/* 476 */     prov.autoProvAccountEager(scheduler);
/*     */     
/* 478 */     List<Account> zimbraAccts = prov.getAllAccounts(zimbraDomain);
/* 479 */     Assert.assertEquals(batchSize, zimbraAccts.size());
/*     */     
/*     */ 
/* 482 */     prov.autoProvAccountEager(scheduler);
/* 483 */     zimbraAccts = prov.getAllAccounts(zimbraDomain);
/* 484 */     Assert.assertEquals(totalAccts, zimbraAccts.size());
/*     */     
/* 486 */     Set<String> acctNames = new HashSet();
/* 487 */     for (Account acct : zimbraAccts) {
/* 488 */       acctNames.add(acct.getName());
/*     */     }
/*     */     
/* 491 */     Assert.assertTrue(acctNames.contains(TestUtil.getAddress(extAcctLocalPart1, zimbraDomain.getName()).toLowerCase()));
/* 492 */     Assert.assertTrue(acctNames.contains(TestUtil.getAddress(extAcctLocalPart3, zimbraDomain.getName()).toLowerCase()));
/* 493 */     Assert.assertTrue(acctNames.contains(TestUtil.getAddress(extAcctLocalPart4, zimbraDomain.getName()).toLowerCase()));
/* 494 */     Assert.assertTrue(acctNames.contains(TestUtil.getAddress(extAcctLocalPart5, zimbraDomain.getName()).toLowerCase()));
/*     */     
/*     */ 
/* 497 */     prov.getLocalServer().unsetAutoProvScheduledDomains();
/*     */   }
/*     */   
/*     */   private static class MockAutoProvisionThread extends AutoProvisionThread
/*     */   {
/*     */     protected long getInitialDelay()
/*     */     {
/* 504 */       return 1L;
/*     */     }
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void eagerModeTimer() throws Exception {
/* 510 */     Config config = prov.getConfig();
/* 511 */     config.setAutoProvPollingInterval("1000ms");
/* 512 */     String testName = getTestName();
/*     */     
/* 514 */     String externalPassword = "test456";
/*     */     
/* 516 */     int totalAccts = 4;
/* 517 */     int batchSize = 1;
/* 518 */     String extAcctLocalPart1 = testName + "_11";
/* 519 */     String extAcctLocalPart2 = "zzz";
/* 520 */     String extAcctLocalPart3 = testName + "_13";
/* 521 */     String extAcctLocalPart4 = testName + "_14";
/* 522 */     String extAcctLocalPart5 = testName + "_15";
/* 523 */     createExternalAcctEntry(extAcctLocalPart1, "test456", null);
/* 524 */     createExternalAcctEntry(extAcctLocalPart2, "test456", null);
/* 525 */     createExternalAcctEntry(extAcctLocalPart3, "test456", null);
/* 526 */     createExternalAcctEntry(extAcctLocalPart4, "test456", null);
/* 527 */     createExternalAcctEntry(extAcctLocalPart5, "test456", null);
/*     */     
/* 529 */     Map<String, Object> zimbraDomainAttrs = AutoProvisionTestUtil.commonZimbraDomainAttrs();
/*     */     
/* 531 */     zimbraDomainAttrs.put("zimbraAutoProvLdapSearchBase", extDomainDn);
/* 532 */     zimbraDomainAttrs.put("zimbraAutoProvLdapSearchFilter", "(&(uid=%u)(mail=eagerMode*)(!(zimbraNotes=PROVISIONED IN ZIMBRA)))");
/*     */     
/*     */ 
/* 535 */     zimbraDomainAttrs.put("zimbraAutoProvAccountNameMap", "uid");
/* 536 */     zimbraDomainAttrs.put("zimbraAutoProvBatchSize", "" + batchSize);
/* 537 */     zimbraDomainAttrs.put("zimbraAutoProvListenerClass", AutoProvisionTestUtil.MarkEntryProvisionedListener.class.getName());
/*     */     
/* 539 */     Domain zimbraDomain = createZimbraDomain(testName, zimbraDomainAttrs);
/*     */     
/*     */ 
/* 542 */     prov.getLocalServer().addAutoProvScheduledDomains(zimbraDomain.getName());
/*     */     
/* 544 */     new MockAutoProvisionThread(null).start();
/*     */     
/* 546 */     Thread.sleep(10000L);
/*     */     
/* 548 */     List<Account> zimbraAccts = prov.getAllAccounts(zimbraDomain);
/* 549 */     Assert.assertEquals(totalAccts, zimbraAccts.size());
/*     */     
/* 551 */     Set<String> acctNames = new HashSet();
/* 552 */     for (Account acct : zimbraAccts) {
/* 553 */       acctNames.add(acct.getName());
/*     */     }
/*     */     
/* 556 */     Assert.assertTrue(acctNames.contains(TestUtil.getAddress(extAcctLocalPart1, zimbraDomain.getName()).toLowerCase()));
/* 557 */     Assert.assertTrue(acctNames.contains(TestUtil.getAddress(extAcctLocalPart3, zimbraDomain.getName()).toLowerCase()));
/* 558 */     Assert.assertTrue(acctNames.contains(TestUtil.getAddress(extAcctLocalPart4, zimbraDomain.getName()).toLowerCase()));
/* 559 */     Assert.assertTrue(acctNames.contains(TestUtil.getAddress(extAcctLocalPart5, zimbraDomain.getName()).toLowerCase()));
/*     */     
/*     */ 
/* 562 */     prov.getLocalServer().unsetAutoProvScheduledDomains();
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/prov/ldap/TestAutoProvision.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */